<template lang="">
  <div class="login_container">
    <div class="login_box">
      <!-- 顶部logo -->
      <div class="top">
        <img src="@/assets/logo.png" alt="">
      </div>
      <!-- form表单 -->
      <el-form ref="formRef" label-width="55px" :model="form" :rules="rules">
        <el-form-item label="账号" prop="username">
          <el-input v-model="form.username"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password" >
          <el-input type="password" v-model="form.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="login">登录</el-button>
          <el-button type="info">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  name: "Login",
  data() {
    return {
      form: {
        username: "admin",
        password: "123456"
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: ['blur'] },
          { min: 5, max: 30, message: "字符长度在5-30之间", trigger: ['blur'] }
        ],
        password: [
          { required: true, message: "请输入密码", trigger: ['blur'] },
          { min: 5, max: 30, message: "字符长度在5-30之间", trigger: ['blur'] }
        ]
      }
    }
  },
  methods: {
    async login() {
      let { data: { data, meta } } = await this.$axios({
        url: "login",
        method: "POST",
        data: this.form
      }).catch(err => err)
      if (meta.status !== 200) return this.$message.error("请求错误")
      sessionStorage.setItem("token", data.token)
      sessionStorage.setItem("username", data.username)
      this.$message.success("成功登录")
      this.$router.push("/")
    }
  }

}
</script>
<style lang="less" scoped>
.login_container {
  width: 100%;
  height: 100%;
  background: #2b4b6b;


  .login_box {
    width: 500px;
    height: 300px;
    border: 1px solid #fff;
    background: white;
    position: absolute;
    left: 50%;
    top: 50%;
    padding: 20px;
    box-sizing: border-box;

    .el-form {
      margin-top: 80px;

      .el-form-item:last-child {
        text-align: center;
      }
    }


    transform: translate(-50%, -50%);

    .top {
      width: 130px;
      height: 130px;
      border: 1px solid #000;
      border-radius: 50%;
      position: absolute;
      left: 50%;
      top: 0px;
      transform: translate(-50%, -50%);
      background: #eeeeee;
      border: 10px solid #fff;
      box-shadow: 0px 0px 10px #fff;


      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;


      }
    }
  }
}
</style>